<?php

namespace app\meizhuangapi\controller\gifts;

use app\api\controller\gifts\UserGifts as UserGiftsCon;
use app\meizhuangapi\model\gifts\UserGifts as UserGiftsModel;
use think\Request;
use think\Db;

/**
 * 用户爆品礼
 */
class UserGifts extends UserGiftsCon{
    /**
     * 已经购买的爆品礼详情
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function buyGiftsDetail(){
        $param = Request::instance()->param();
        $model = UserGiftsModel::buyGetDetail($param['user_gifts_id']);
        if(empty($model)){
            return $this->renderError('爆品礼不存在，请刷新后重试');
        }
        $model['gifts_content'] = htmlspecialchars_decode($model['gifts_content']);
        //获取店铺信息
        //获取店铺头像，名称
        $storeInfo=Db::name('store_shop')->where(['wxapp_id'=>input('post.wxapp_id')])->find();
        //获取头像，资质图片
        $tx=Db::name('upload_file')->where(['file_id'=>$storeInfo['logo_image_id']])->find();
        //$zz=Db::name('upload_file')->where(['file_id'=>$storeInfo['image_id_yyzz']])->find();
        $storeInfo['headImageUrl']=$tx['file_url'].'/'.$tx['file_name'];
        //获取订单信息
        $orderInfo=Db::name('gifts_order')->where(['order_id'=>$model['order_id']])->find();
        $orderInfo['pay_time']=date('Y-m-d h:i:s',$orderInfo['pay_time']);
        $model['storeInfo']=$storeInfo;
        $model['orderInfo']=$orderInfo;
        //$model['orderInfo']['pay_time']=date('Y-m-d h:i:s',$orderInfo['pay_time']);
        return $this->renderSuccess($model);
    }
}